package cn.tedu._03_vehicle.base.interceptor;

import cn.tedu._03_vehicle.base.response.JsonResult;
import cn.tedu._03_vehicle.base.response.StatusCode;
import cn.tedu._03_vehicle.pojo.vo.UserRegQuery;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //1获取回话参数/*
        HttpSession session = request.getSession();
        // 2、获取会话标识getattribute("user")
        //Object user = session.getAttribute("user");
        // 3\登录--放行
        // 4、未登录，就跳转到登录界面
        UserRegQuery userRegQuery = (UserRegQuery) session.getAttribute("user");
        if (userRegQuery==null){//检验登录状态
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
